<?php include"shared/head.php";
include"shared/log.php";?>

<?php
$filename=$_FILES["file"]["name"];
if ($_FILES["file"]["error"]>0)
{
    echo $s_uploaded_uplderror.$_FILES["file"]["error"];
}

else{
    if (file_exists("upload/".$filename))
    {
        echo $s_uploaded_filename_existed;
    }
    else{
        move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$filename);
    }
}

include "Classes/PHPExcel.php";
$file_now="upload/".$filename;
$excel=PHPExcel_IOFactory::load($file_now);
$sheetcount=$excel->getSheetCount();
    for($i=0;$i<$sheetcount;$i++)
        {
            $data=$excel->getSheet($i)->toArray();
            for($j=1;$j<count($data);$j++)
                {
                    $source=$data[$j][0];
                    $target=$data[$j][0];

                    include "shared/conn.php";
                    mysqli_select_db( $conn,"personalterm");
                    mysqli_query($conn, "set names 'utf-8");

                    $sql="INSERT INTO `term`(zh_CN,en_US) VALUES('$source','$target')";
                    $result=mysqli_query($conn,$sql);

                        if(!$result)
                        {
                            echo $s_uploaded_file_insertintodb_error;
                        }
                }
        }
echo "<script>alert('{$s_upld_sucs}')</script>";
echo "<script>location='index.php'</script>";
?>

<?php include"shared/foot.php";?>